home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-04 | 3.9 KB | 116 lines | [TEXT/MPS ] |
- # **********************************************************************
- # File: Script 3.vu
- #
- # Purpose: to demonstrate flow-control concepts
- #
- # Prerequisites: This script assumes that DrawShapesVU is the
- # currently active application on the target.
- #
- # Notes: If an attempt is made to draw a shape and the shape
- # does not materialize, it may be because the shape
- # drawn is smaller than DrawShapeVU's minimum shape
- # size. It is not a problem with VU. The number of
- # shapes that will be drawn can be changed by altering
- # the gMaxIterations variable.
- #
- # Written by: David Gaxiola
- #
- # Copyright © 1992 by Apple Computer, Inc., all rights reserved.
- #
- # **********************************************************************
-
- # global variable definitions ******************************************
- # All global variables begin with a lowercase “g”
- gToolColumn := 18;
- gToolRow := { 40, 80, 120 ,160 };
- gWindowMod := { 41, 21, -21, -21 };
- gWindowDim := { };
- gScreenDim := { };
- gMaxIterations := 4;
- gSaveAsFilename := 'Tutorial 3 Example.ds';
- gMinimumShapeSize := { 40, 40 }; # minimum size for all shapes
- # Begin main body. *************************************************
-
- # preliminary setup:
-
- MouseSpeed(10);
- Patience(2);
-
- # Get information about the screen.
- match [ screen rectangle:?gScreenDim menubar:true ];
- match [ menu title:?FifthMenu ordinality:5 ];
-
- # Create a new file.
- println "# Setting up new DrawShapes document.";
- select [ menuItem title:'New' m:[menu title:'File' ]];
- drag [ window title:/Untitled-≈/ ordinality:1 ] absolute:{ 1, 21 };
- size [ window title:/Untitled-≈/ ordinality:1 ]
- width:( gScreenDim[3] - 2 ) height:( gScreenDim[4] - 22 );
- match [ window rectangle:?gWindowDim ordinality:1 ];
-
- # Note how one for loop takes the place of dozens of lines of code!
- # The "for...each" loop works similarly, but with lists.
- for currentIteration := 1 to gMaxIterations do
- begin
- println "# Performing editing. Loop {currentIteration} of {gMaxIterations}.";
- thisRandomTool := Random( 2, 4 );
- move absolute:{ (gWindowDim[1] + gToolColumn),
- (gWindowDim[2] + gToolRow[thisRandomTool]) };
- click;
- xStart := Random( (gWindowDim[1] + gWindowMod[1]),
- (gWindowDim[3] + gWindowMod[3])/2 ); # x-coordinate in left half of window
- xStop := Random( (xStart+gMinimumShapeSize[1]),
- (gWindowDim[3] + gWindowMod[3]) ); # x-coordinate which meets the minimum requirement
- yStart := Random( (gWindowDim[2] + gWindowMod[2]),
- (gWindowDim[4] + gWindowMod[4])/2 ); # y-coordinate in upper half of window
- yStop := Random( (yStart + gMinimumShapeSize[2]),
- (gWindowDim[4] + gWindowMod[4]) ); # y-coordinate which meets the minimum requirement
- move absolute:{ xStart, yStart };
- pressMouse;
-
- # wait statement for slow targets
-
- wait(1);
- move absolute:{ xStop, yStop };
- releaseMouse;
-
- # The if...do...else statement can be used to check for
- # changing cases.
-
- if ( FifthMenu = 'Colors' ) do
- begin
- theRandomOrder := Random( 1, 7 );
- select[ menuItem ordinality:theRandomOrder
- menu:[ menu title:'Colors' ]];
- end;
- end;
-
-
- # Save file with the filename specified in the "gSaveAsFilename"
- # variable
-
- println "# Saving and closing document.";
- select [ menuItem title:/Save As≈/ menu:[ menu title:'File' ]];
- Wait(1); ### for slower targets
- type keystrokes:{ gSaveAsFilename, returnKey };
-
- # The next if control structure checks to see if another dialog box
- # appears indicating that a file already exists with the same name as
- # thag ] do fied with the gSaveAsFilename variable. If the file is
- # already there, VU overwrites the file.
-
- if match [ window style:dialog ] do
- begin
- if match [ button title:'Yes' ] do
- begin
- select [ button title:'Yes' ];
- end;
- else if match [ button title:'Replace' ] do
- begin
- select [ button title:'Replace' ];
- end;
- end;
-
- close [ window title:gSaveAsFilename ];
- # End main body. *************************************************
-